package com.example.cloudpracticeplatform.controller;

import com.example.cloudpracticeplatform.common.Response;
import com.example.cloudpracticeplatform.service.EnrollmentService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/enrollment")
@CrossOrigin
public class EnrollmentController {
    @Resource
    private EnrollmentService enrollmentService;

    @PostMapping("/enroll")
    public Response enrollCourse(@RequestParam Integer studentId, @RequestParam Integer courseId) {
        try {
            boolean success = enrollmentService.enrollCourse(studentId, courseId);
            if (success) {
                return Response.success("Course enrolled successfully");
            } else {
                return Response.error("Failed to enroll course");
            }
        } catch (Exception e) {
            return Response.error("An error occurred: " + e.getMessage());
        }
    }
}